package com.examplemartin.jpademo.pojo.po;

import com.examplemartin.jpademo.annotation.EntityCheck;
import com.examplemartin.jpademo.pojo.admin.BaseEntity;
import com.examplemartin.jpademo.pojo.po.purchase.PurPO;
import com.examplemartin.jpademo.pojo.po.repository.purchase.PurInPO;
import com.examplemartin.jpademo.pojo.po.repository.sell.SellOutPO;
import com.examplemartin.jpademo.pojo.po.sell.SellPO;
import com.examplemartin.jpademo.pojo.po.stock.StockPO;
import java.io.Serializable;
import java.util.List;
import javax.persistence.*;

import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.hibernate.annotations.Fetch;
import org.hibernate.annotations.FetchMode;

/**
 * 用户表
 */
@Data
@EqualsAndHashCode(callSuper = true)
@Entity(name = "t_user")
public class UserPO extends BaseEntity implements Serializable {

  public static final Integer USER_STATUS_NORAML = 1;
  public static final Integer USER_STATUS_LOCK = -1;
  public static final Integer USER_GENDER_MALE = 1;
  public static final Integer USER_GENDER_FEMALE = -1;
  public static final Integer USER_GENDER_SECRITY = 0;


  @EntityCheck(required = true, errRequired = "必须输入用户姓名")
  private String username;

  @EntityCheck(required = true, errRequired = "必须输入用户登入")
  private String loginname;
  @EntityCheck(required = true, errRequired = "必须输入登入密码")
  private String password;

  private String userPic;

  private String phone;
  private String email;

  private Integer status = USER_STATUS_NORAML;
  private Integer gender = USER_GENDER_SECRITY;

  @ManyToOne
  @JoinColumn(name = "role_id")
  private RolePO role;

  private String comment;

  // 仓库 one
  @ManyToOne
  private StockPO stockPO;

  /**
   * 销售员部分
   */
  // 销售退货订单 list

  // 销售订单 list
   @OneToMany(fetch = FetchType.EAGER,mappedBy = "userPO")
   @Fetch(FetchMode.SUBSELECT)
   @JsonIgnore
  private List<SellPO> sellPOList;

  /**
   * 采购员部分
   */
  // 采购订单 list
   @OneToMany(mappedBy = "userPO")
   @Fetch(FetchMode.SUBSELECT)
   @JsonIgnore
  private List<PurPO> purPOList;


  /**
   * 仓管员部分
   */
  // 销售订单出库单 list
   @OneToMany(fetch = FetchType.EAGER,mappedBy = "userPO")
   @Fetch(FetchMode.SUBSELECT)
   @JsonIgnore
  private List<SellOutPO> sellOutPOList;

  // 采购订单入库单 list
   @OneToMany(mappedBy = "userPO")
   @Fetch(FetchMode.SUBSELECT)
   @JsonIgnore
  private List<PurInPO> purInPOList;



    @Override
    public String toString() {
        return "UserPO{" +
                "username='" + username + '\'' +
                ", loginname='" + loginname + '\'' +
                ", password='" + password + '\'' +
                ", userPic='" + userPic + '\'' +
                ", phone='" + phone + '\'' +
                ", email='" + email + '\'' +
                ", status=" + status +
                ", gender=" + gender +
                ", role=" + role +
                ", comment='" + comment + '\'' +
                ", stockPO=" + stockPO +
                '}';
    }
}
